﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using HZ.MBSM.DBUtility;
using System.Web.UI.WebControls.WebParts;

public partial class Bidder_SetCompanyTB : System.Web.UI.Page
{
    string strSql;
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType =
            new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))  //是否为合法用户
        { 
            if (!IsPostBack)
            {
                Db DbProject = new Db();
                strSql = "select projectid,ProjectMarker,Title from project order by projectid ";
                System.Data.IDataReader dr = DbProject.DataReader(strSql);
                listProject.DataSource = dr;
                listProject.DataTextField = "Title";
                listProject.DataValueField = "projectid";
                listProject.DataBind();
                dr.Close();
                dr = null;
                DbProject.Close();
            }
            showGridView();
        }
    }
    public void showGridView()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "v_product_goods as a left join bid_Goods_TBR  as b on a.goodsid=b.goodsid  inner join bid_project_product d on a.productid=d.productid ";                                               //要查询的表明
        dbPage.Key = "a.goodsid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "a.goodsid,a.productname,a.Medicinemodel,a.Outlookc,a.Unit,a.xishu,b.Accountid_TB,b.usercode_TB ,b.username_Tb,b.Accept_time, case status when 0 then '未确认' when 1 then '已确认'  when 2 then '已撤销' else '未设置' end as status";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第.几页   
        dbPage.PageSize = 15;                                                    //没有显示记录条数   
        dbPage.OrderBy = "a.goodsid,a.productname";        //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }
    public string fctConditions()
    {
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        Session["Projectid"] = listProject.SelectedValue;
        // 所有确认投标的d.projectid=" + listProject.SelectedValue 的商品列表
        string strwhere = " (a.ifbid<>0 or a.ifbid is null )and a.checkstatus=1 and d.projectid=" + listProject.SelectedValue + " and a.AccountId_TJR='" + _Account.AccountId + "'";
        if (txtProductName.Text.ToString().Trim() != "")
        {
            strwhere += " and a.productname like '%" + txtProductName.Text.ToString().Trim() + "%'";
        }
        return strwhere;

    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "SetTBR")//e.CommandName.CompareTo("SetTBR") == 0 
        {            
           // int rowID = Convert.ToInt32(e.CommandArgument);获取参数值
            int rowIndex = ((GridViewRow)((Button)e.CommandSource).NamingContainer).RowIndex;
            Label1.Text = GridView1.DataKeys[rowIndex].Value.ToString();

           // Server.Transfer("GoodDetail.aspx?GoodsId=" + rowID.ToString());

        }
    }

   // protected void LinkButton1_Command(object sender, CommandEventArgs e)
   //{
   //       LinkButton lb = (LinkButton)sender;
   //       DataControlFieldCell dcf = (DataControlFieldCell)lb.Parent;
   //       GridViewRow gvr = (GridViewRow)dcf.Parent;
   //       GridView1.SelectedIndex = gvr.RowIndex;
   //   }
    
}
